package view
{
	
	import flash.display.*;
	import flash.text.TextField;
	
	import model.*;
	
	/**
	 * -- UserInfoBoardView --
	 * @desc	view of user's info board at the top of stage
	 * @author	Aqua (built on 2011-11-09)
	 */
	public class UserInfoBoardView extends BaseView
	{
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * -- UserInfoBoardView --
		 * @desc		constructor
		 * @param		main view object of this view class
		 *************************************************************************/
		public function UserInfoBoardView(viewComponent:DisplayObjectContainer):void
		{
			super(viewComponent);
			
			_viewComponent.name = VIEW_NAME;
			_userPx = getPx(UserPx.NAME) as UserPx;
			
			addAddCmd("image_user",			add_image_user);
			addAddCmd("image_chara",		add_image_chara);
			addAddCmd("member_0",			add_member);
			addAddCmd("member_1",			add_member);
			addAddCmd("member_2",			add_member);
			addAddCmd("txt_name",			add_txt_name);
			addAddCmd("txt_power",			add_txt_power);
			addAddCmd("txt_gold",			add_txt_gold);
			addAddCmd("txt_hp",				add_txt_hp);
			addAddCmd("txt_num_duel",		add_txt_num_duel);
			addAddCmd("txt_num_win",		add_txt_num_win);
			addAddCmd("txt_num_duel_left",	add_txt_num_duel_left);
			addAddCmd("txt_win_rate",		add_txt_win_rate);
			addAddCmd("txt_win_series",		add_txt_win_series);
			addAddCmd("txt_lose_series",	add_txt_lose_series);
			addAddCmd("txt_current_series",	add_txt_current_series);
			addAddCmd("txt_level_chara",	add_txt_level_chara);
			
			addClickCmd("image_user",	click_image_user);
		}
		
		
		//------------------//
		//     Privates     //
		//------------------//
		
		//-- Add Handlers --//
		private function add_image_user():void
		{
			
		}
		private function add_image_chara():void
		{
			
		}
		private function add_member():void
		{
			
		}
		private function add_txt_name():void
		{
			TextField(_display).text = _userPx.userVO.name;
		}
		private function add_txt_power():void
		{
			TextField(_display).text = String(_userPx.getPower());
		}
		private function add_txt_gold():void
		{
			TextField(_display).text = String(_userPx.userVO.gold);
		}
		private function add_txt_hp():void
		{
			TextField(_display).text = String(_userPx.userVO.hp);
		}
		private function add_txt_num_duel():void
		{
			TextField(_display).text = String(_userPx.userVO.numDuel);
		}
		private function add_txt_num_win():void
		{
			TextField(_display).text = String(_userPx.userVO.numWin);
		}
		private function add_txt_num_duel_left():void
		{
			TextField(_display).text = String(_userPx.userVO.numDuelLeft);
		}
		private function add_txt_win_rate():void
		{
			var rate:String;
			var dotIndex:int;
			
			if (0 == _userPx.userVO.numWin)
			{
				TextField(_display).text = "0.0%";
			}
			else
			{
				rate = String(_userPx.userVO.numWin / _userPx.userVO.numDuel * 100);
				dotIndex = rate.indexOf(".");
				TextField(_display).text = rate.substring(0, dotIndex + 1) + "%";
			}
		}
		private function add_txt_win_series():void
		{
			TextField(_display).text = String(_userPx.userVO.winSeries);
		}
		private function add_txt_lose_series():void
		{
			TextField(_display).text = String(_userPx.userVO.loseSeries);
		}
		private function add_txt_current_series():void
		{
			//TextField(_display).text = String(_userPx.userVO.currentSeries);
		}
		private function add_txt_level_chara():void
		{
			TextField(_display).text = String(_userPx.userVO.gold);
		}
		
		//-- Click Handlers --//
		private function click_image_user():void
		{
			// just for test
			_userPx.updateUserData(response);
			
			function response():void
			{
				
			}
		}
		
		
		public static const VIEW_NAME	:String = "USER_INFO_BOARD";
		public static const LAYER_INDEX	:int	= 4;
		
		private var _userPx	:UserPx;
	}
	
}